﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EEA.SOACommerce.Shared.ServiceContracts.ServiceInterface;
using EEA.SOACommerce.Shared.ServiceClients.Config;
using EEA.SOACommerce.Shared.ServiceContracts.CatalogService;
using EEA.SOACommerce.Shared.ServiceContracts;

namespace EEA.SOACommerce.Shared.ServiceClients
{
    public sealed class CatalogServiceClient
    {
        private ICatalogService service;
        private static volatile CatalogServiceClient instance;
        private static object syncRoot = new Object();

        private CatalogServiceClient()
        {

            ServiceClientConfiguration config = new ServiceClientConfiguration
            {
                Location = "",
                MaxArrayLength = 163840,
                MaxBufferSize = 6553600,
                MaxBytesPerRead = 8192,
                MaxDepth = 1024,
                MaxItemsInObjectGraph = int.MaxValue,
                MaxReceivedMessageSize = 6553600,
                MaxStringContentLength = 262144,
                TimeOutInMinute = 3
            };
            this.service = ServiceClientBuilder.Build<ICatalogService>(config);
        }

        public static CatalogServiceClient GetInstance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new CatalogServiceClient();
                    }
                }

                return instance;
            }
        }



        public List<Category> GetCategoryList(CommerceContext context)
        {
            CategoryQueryResponse response = this.service.GetCategories(new CategoryQueryRequest { });
            return response.CategoryList;

        }
    }
}
